'''
BM15 删除有序链表中重复的元素-I
'''

class ListNode:
    def __init__(self,val,next=None):
        self.val = val
        self.next = next


class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        # write code here
        if head == None:
            return head

        cur = head
        while cur and cur.next:
            temp = cur.next
            if cur.val == temp.val:
                cur.next = temp.next
            else:
                cur = temp
        return head

def printList(node: ListNode):
    while node:
        print(node.val, end="->" if node.next else "\n")
        node = node.next

if __name__ == "__main__":
    node = ListNode(1, ListNode(1, ListNode(2, ListNode(2, ListNode(3)))))
    node2 = ListNode(1, ListNode(1, ListNode(1)))
    listnode = Solution().deleteDuplicates(node)
    listnode2 = Solution().deleteDuplicates(node2)
    printList(listnode)
    printList(listnode2)
